package com.learn.mvc.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MessageHandler {

    Logger logger = LoggerFactory.getLogger(this.getClass());


    @RequestMapping("/throw/arithmetic/exception")
    public String throwArithmeticException() {
        System.out.println(10 / 0);
        return "target";
    }
    @RequestMapping("/throw/null/pointer/exception")
    public String throwNullPointerException() {
        String a = null;
        System.out.println(a.length());
        return "target";
    }

    @RequestMapping("/throw/out/of/index/exception/common")
    public String throwOutOfIndexException() {
        int[] array = new int[10];
        System.out.println(array[15]);
        return "target";
    }

    @ResponseBody
    @RequestMapping("/throw/out/of/index/exception/ajax")
    public String throwOutOfIndexExceptionAjax() {
        int[] array = new int[10];
        System.out.println(array[15]);
        return "message from server";
    }


}
